<template>
  <a-modal :maskClosable="false"
    :title='title'
    :width='1248'
    :visible='visible'
    :confirmLoading='confirmLoading'
    @ok='handleOk'
    @cancel='handleCancel'
    cancelText='关闭'>

    <a-spin :spinning='confirmLoading'>
      <a-tabs default-active-key='1'>
        <a-tab-pane key='1' tab='基本计划信息'>
          <a-form-model ref='form' v-bind='layout' :model='model' :rules='validatorRules'>
            <a-row>
              <a-col span="12">
                <a-form-model-item label="计划标题" prop="planTitle">
                  <a-input  v-model="model.planTitle"  placeholder="请输入计划标题"/>
                </a-form-model-item>
              </a-col>
              <a-col span="12">
              </a-col>
            </a-row>
            <a-row>
              <a-col span='12'>
                <a-form-model-item label='开始日期' prop='startTime'>
                  <a-date-picker placeholder='请输入日期' format='YYYY-MM-DD' valueFormat='YYYY-MM-DD'  v-model='model.startTime' />
                </a-form-model-item>
              </a-col>
              <a-col span='12'>
                <a-form-model-item label='结束日期' prop='endTime'>
                  <a-date-picker placeholder='请输入日期' format='YYYY-MM-DD' valueFormat='YYYY-MM-DD'
                                 v-model='model.endTime' />
                </a-form-model-item>
              </a-col>
            </a-row>
            <a-row>
              <a-col span='12'>
                <a-form-model-item label='完成执行次数(次/月)' required prop='execCount'>
                  <a-input placeholder='请输入完成执行次数(次/月)' v-model='model.execCount' style='width: 200px'  />
                </a-form-model-item>
              </a-col>
              <a-col span='12'>

              </a-col>
            </a-row>

            <a-row>
              <a-col span='12'>
                <a-form-model-item label='执行人类型' required prop='execType'>
                  <a-radio-group v-model='model.execType' disabled='disabled'>
                    <a-radio value='0'>
                      社区
                    </a-radio>
                    <a-radio value='1'>
                      内部职工
                    </a-radio>
                  </a-radio-group>
                </a-form-model-item>
              </a-col>
              <a-col span='12'>
                <a-form-model-item label='负责人' required prop='eyName'>
                  <a-input-search placeholder="请输入负责人" v-model="model.eyName" style="width: 200px" enter-button
                                  @search="onSearch" />
                </a-form-model-item>
              </a-col>
            </a-row>
            <a-row justify='start'>
              <a-form-item label='计划走访事务' required prop='followUpContent' :label-col='{span: 3 }'
                           :wrapperCol='{span: 20 }'>
                <a-textarea v-model='model.followUpContent' style='height: 300px' ></a-textarea>
              </a-form-item>
            </a-row>
          </a-form-model>
        </a-tab-pane>
        <a-tab-pane key='2' tab='服务对像' force-render>
          <a-row :gutter='18'  style="margin-top: 10px">
            <a-col :span='22'>
              <!-- 查询区域 -->
              <a-form layout='inline' class='j-inline-form'>
                <!-- 固定条件 -->
                <a-form-item label='长者姓名'>
                  <a-input placeholder='请输入长者姓名' v-model='queryParam.patientName'></a-input>
                </a-form-item>
                <a-button type='primary' @click='searchQuery' icon='search'>查询</a-button>
                <a-button type='primary' @click='searchReset' icon='reload' style='margin-left: 8px'>重置</a-button>
              </a-form>
              <a-table
                style="margin-top: 10px"
                size='middle'
                bordered
                rowKey='id'
                :columns='columns'
                :dataSource='dataSource'
                :pagination='ipagination'
                :loading='loading'
                @change='handleTableChange'>
                 <span slot="action" slot-scope="text, record">
                  <a @click="postSubmit(record.id,'确认要删除此会员的访问任务吗？','/ch/interview/detail/delete')">删除</a>
                </span>
              </a-table>
            </a-col>
          </a-row>
        </a-tab-pane>
      </a-tabs>

      <employee-dialog ref='employeeModal' @signOk='handleSignChoice'></employee-dialog>
    </a-spin>
  </a-modal>
</template>

<script>
import { httpAction, putAction, getAction, postAction } from '@api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { pushIfNotExist } from '@/utils/util'
import EmployeeDialog from '@views/his/dialog/EmployeeDialog'

export default {
  name: 'hHisInterviewPlanModal',
  mixins: [JeecgListMixin],
  components: {
    EmployeeDialog,
  },
  data() {
    return {
      title: '操作',
      visible: false,
      disableMixinCreated:true,
      model: {
        eyName: '',
        eyId: 0
      },
      layout: {
        labelCol: { span: 6 },
        wrapperCol: { span: 14 }
      },
      confirmLoading: false,
      validatorRules: {
        planTitle: [{ required: true, message: '请输入计划标题!' }],
        year: [{ required: true, message: '请输入执行年!' }],
        serviceQty: [{ required: true, message: '请输入服务人数!' }],
        execCount: [{ required: true, message: '请输入执行次数(次/月)!' }],
        execType: [{ required: true, message: '请输入执行人类型!' }],
        eyName: [{ required: true, message: '请输入负责人!' }],
        followUpContent: [{ required: true, message: '请输入计划走访事务!' }]
      },
      url: {
        add: '/ch/interview/plan',
        edit: '/ch/interview/plan',
        list: '/ch/interview/detail/list'
      },
      queryParam: { source: '1' },
      columns: [
        {
          title: '长者姓名',
          align: 'center',
          dataIndex: 'patientName'
        },
        {
          title: '性别',
          align: 'center',
          dataIndex: 'patientSex'
        },
        {
          title: '年龄(岁)',
          align: 'center',
          dataIndex: 'patientAge'
        },
        { title: '操作', dataIndex: 'action', align: 'center', width: 120, scopedSlots: { customRender: 'action' } }
      ],
    }
  },

  created() {
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    /** 删除已选择的 */
    edit(record) {
      const that = this
      that.model = Object.assign({}, record)
      that.visible = true
      that.queryParam.planCode = record.planCode
      that.loadData()
    },
    close() {
      this.$refs.form.clearValidate()
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true
          that.model.planType = '2'
          putAction(that.url.edit, this.model).then((res) => {
            if (res.success) {
              that.$message.success(res.message)
              that.$emit('ok')
              that.close()
            } else {
              that.$message.warning(res.message)
            }
          }).finally(() => {
            that.confirmLoading = false
          })
        } else {
          return false
        }
      })
    },
    handleCancel() {
      this.close()
    },
    onSearch() {
      this.$refs.employeeModal.show()
      this.$refs.employeeModal.disableSubmit = false
    },
    onChange: function(e) {
      //社工
      if (e.target.value == '0') {
        this.$refs.butlerModal.show(false)
        this.$refs.butlerModal.disableSubmit = false
      } else {
        this.$refs.employeeModal.show()
        this.$refs.employeeModal.disableSubmit = false
      }
    },
    handleSignChoice(record) {
      if (this.model.execType == '1') {
        this.model.eyName = record.name
        this.model.eyId = record.id
      } else {
        this.model.eyName = record.name
        this.model.eyId = record.id
      }
    },
  }
}
</script>

<style scoped>

</style>